import {createRouter, createWebHashHistory, RouteRecordRaw} from "vue-router";
import { usePermissStore } from '../store/permiss'
import Home from "../views/Home.vue";

const routes:RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/dashboard'
    }, {
        path: "/",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/dashboard",
                name: "dashboard",
                meta: {
                    title: '系统首页',
                    permiss: '1'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/Dashboard.vue")
            },
            {
                path: "/table_employee",
                name: "table_employee",
                meta: {
                    title: '人员管理',
                    permiss: '2'
                },
                component: () => import ( /* webpackChunkName: "permission" */ "../views/table_employee.vue")
            },
            {
                path: "/table_jy",
                name: "table_jy",
                meta: {
                    title: '卷烟信息管理',
                    permiss: '3'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_jy.vue")
            },
            {
                path: "/table_wd",
                name: "table_wd",
                meta: {
                    title: '烟草网点管理',
                    permiss: '4'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_wd.vue")
            },
            {
                path: "/table_rule",
                name: "table_rule",
                meta: {
                    title: '处罚条例管理',
                    permiss: '5'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_rule.vue")
            },
            {
                path: "/table_history",
                name: "table_history",
                meta: {
                    title: '历史案件',
                    permiss: '6'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_history.vue")
            },
            {
                path: "/table_ocr",
                name: "table_ocr",
                meta: {
                    title: '扫描纸质文档',
                    permiss: '7'
                },
                component: () => import ( /* webpackChunkName: "permission" */ "../views/table_ocr.vue")
            },
            {
                path: "/table_process",
                name: "table_process",
                meta: {
                    title: '审核管理',
                    permiss: '8'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_process.vue")
            },
            {
                path: "/table_analysis",
                name: "table_analysis",
                meta: {
                    title: '案件分析',
                    permiss: '1'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_analysis.vue")
            },
            {
                path: "/table_analysis_tree",
                name: "table_analysis_tree",
                meta: {
                    title: '案件分析树形图',
                    permiss: '1'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_analysis_tree.vue")
            },
            {
                path: "/table_analysis_radar",
                name: "table_analysis_radar",
                meta: {
                    title: '案件分析雷达图',
                    permiss: '1'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_analysis_radar.vue")
            },
            // {
            //     path: "/table_case",
            //     name: "table_case",
            //     meta: {
            //         title: '案件管理',
            //         permiss: '3'
            //     },
            //     component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_case.vue")
            // },
            // {
            //     path: "/table_delivery_channel",
            //     name: "table_delivery_channel",
            //     meta: {
            //         title: '寄递渠道涉烟信息管理',
            //         permiss: '32'
            //     },
            //     component: () => import ( /* webpackChunkName: "dashboard" */ "../views/table_delivery_channel.vue")
            // },
            {
                path: "/evidence",
                name: "evidence",
                meta: {
                    title: '现场证据文件管理',
                    permiss: '9'
                },
                children:[
                    {
                        path: "/evidence_image",
                        name: "evidence_image",
                        meta: {
                            title: '证据照片管理',
                            permiss: '10'
                        },
                        component: () => import ( /* webpackChunkName: "dashboard" */ "../views/evidence_image.vue")
                    },
                    {
                        path: "/table_evidence",
                        name: "table_evidence",
                        meta: {
                            title: '证据先行保存通知书管理',
                            permiss: '11'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_evidence.vue")
                    },
                    {
                        path: "/table_record",
                        name: "table_record",
                        meta: {
                            title: '勘验笔录',
                            permiss: '13'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_record.vue")
                    },
                    {
                        path: "/table_cigCode",
                        name: "table_cigCode",
                        meta: {
                            title: '卷烟喷码管理',
                            permiss: '14'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_cigCode.vue")
                    },

                ]
            },

            {
                path: "/table_reports",
                name: "table_reports",
                meta: {
                    title: '文档报表管理',
                    permiss: '15'
                },
                children:[
                    {
                        path: "/table_report",
                        name: "table_report",
                        meta: {
                            title: '立案报告表',
                            permiss: '16'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_report.vue")
                    },
                    {
                        path: "/table_identify",
                        name: "table_identify",
                        meta: {
                            title: '卷烟鉴别书',
                            permiss: '19'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_identify.vue")
                    },
                    {
                        path: "/table_cigPrice",
                        name: "table_cigPrice",
                        meta: {
                            title: '涉案烟草核价表管理',
                            permiss: '20'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_cigPrice.vue")
                    },

                    {
                        path: "/table_inquiry_record",
                        name: "table_inquiry_record",
                        meta: {
                            title: '询问笔录',
                            permiss: '21'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_inquiry_record.vue")
                    },
                    {
                        path: "/table_end_report",
                        name: "table_end_report",
                        meta: {
                            title: '调查终结文书管理',
                            permiss: '22'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_end_report.vue")
                    },

                ]
            },
            {
                path: "/discuss_hear",
                name: "discuss_hear",
                meta: {
                    title: '讨论听证管理',
                    permiss: '23'
                },
                children:[
                    {
                        path: "/table_group_discussion",
                        name: "table_group_discussion",
                        meta: {
                            title: '集体讨论',
                            permiss: '24'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_group_discussion.vue")
                    },
                    {
                        path: "/table_hear_notice",
                        name: "table_hear_notice",
                        meta: {
                            title: '听证告知书',
                            permiss: '25'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_hear_notice.vue")
                    },

                ]
            },
            {
                path: "/table_punish",
                name: "table_punish",
                meta: {
                    title: '案件处理管理',
                    permiss: '26'
                },
                children:[
                    {
                        path: "/table_case_handle",
                        name: "table_case_handle",
                        meta: {
                            title: '案件处理审批管理',
                            permiss: '27'
                        },
                        component: () => import ( /* webpackChunkName: "form" */ "../views/table_case_handle.vue")
                    },
                    {
                        path: "/table_advance_penalty",
                        name: "table_advance_penalty",
                        meta: {
                            title: '行政处罚事先告知书',
                            permiss: '28'
                        },
                        component: () => import ( /* webpackChunkName: "permission" */ "../views/table_advance_penalty.vue")
                    },
                    {
                        path: "/table_punish_decision",
                        name: "table_punish_decision",
                        meta: {
                            title: '行政处罚决定书',
                            permiss: '29'
                        },
                        component: () => import ( /* webpackChunkName: "permission" */ "../views/table_punish_decision.vue")
                    },
                    {
                        path: "/table_administrative_fine",
                        name: "table_administrative_fine",
                        meta: {
                            title: '行政罚款收据',
                            permiss: '30'
                        },
                        component: () => import ( /* webpackChunkName: "permission" */ "../views/table_administrative_fine.vue")
                    },

                    {
                        path: "/table_final_report",
                        name: "table_final_report",
                        meta: {
                            title: '结案报告表管理',
                            permiss: '31'
                        },
                        component: () => import ( /* webpackChunkName: "permission" */ "../views/table_final_report.vue")
                    },
                    {
                        path: "/table_archive_file",
                        name: "table_archive_file",
                        meta: {
                            title: '归档管理',
                            permiss: '32'
                        },
                        component: () => import ( /* webpackChunkName: "permission" */ "../views/table_archive_file.vue")
                    }

                ]
            },



            // {
            //     path: "/icon",
            //     name: "icon",
            //     meta: {
            //         title: '自定义图标',
            //         permiss: '6'
            //     },
            //     component: () => import ( /* webpackChunkName: "permission" */ "../views/icon.vue")
            // },
            // {
            //     path: "/charts",
            //     name: "charts",
            //     meta: {
            //         title: '自定义图标',
            //         permiss: '6'
            //     },
            //     component: () => import ( /* webpackChunkName: "permission" */ "../views/charts.vue")
            // },
        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import ( /* webpackChunkName: "login" */ "../views/Login.vue")
    },
    {
        path: '/403',
        name: '403',
        meta: {
            title: '没有权限'
        },
        component: () => import (/* webpackChunkName: "403" */ '../views/403.vue')
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | vue-manage-system`;
    const role = localStorage.getItem('ms_username');
    const permiss = usePermissStore();
    if (!role && to.path !== '/login') {
        next('/login');
    }
    else if (to.meta.permiss && !permiss.key.includes(to.meta.permiss)) {
        // 如果没有权限，则进入403
        // next('/403');
        alert("您没有权限进入，有需要请联系管理人员！");
        return false;

    } else {
        next();
    }
});

export default router;
